package com.ruoyi.web.controller.emergency;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.emergency.domain.EmergencyDeviceClass;
import com.ruoyi.emergency.service.IEmergencyDeviceClassService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 应急救援物资种类Controller
 * 
 * @author hcc
 * @date 2024-11-17
 */
@RestController
@RequestMapping("/control/emergencyClass")
public class EmergencyDeviceClassController extends BaseController
{
    @Autowired
    private IEmergencyDeviceClassService emergencyDeviceClassService;

    /**
     * 查询应急救援物资种类列表
     */
    //@PreAuthorize("@ss.hasPermi('control:emergencyClass:list')")
    @GetMapping("/list")
    @ApiOperation("应急救援物资种类")
    public TableDataInfo list(EmergencyDeviceClass emergencyDeviceClass)
    {
        startPage();
        List<EmergencyDeviceClass> list = emergencyDeviceClassService.selectEmergencyDeviceClassList(emergencyDeviceClass);
        return getDataTable(list);
    }

    /**
     * 导出应急救援物资种类列表
     */
    @PreAuthorize("@ss.hasPermi('control:emergencyClass:export')")
    @Log(title = "应急救援物资种类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EmergencyDeviceClass emergencyDeviceClass)
    {
        List<EmergencyDeviceClass> list = emergencyDeviceClassService.selectEmergencyDeviceClassList(emergencyDeviceClass);
        ExcelUtil<EmergencyDeviceClass> util = new ExcelUtil<EmergencyDeviceClass>(EmergencyDeviceClass.class);
        util.exportExcel(response, list, "应急救援物资种类数据");
    }

    /**
     * 获取应急救援物资种类详细信息
     */
    @PreAuthorize("@ss.hasPermi('control:emergencyClass:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(emergencyDeviceClassService.selectEmergencyDeviceClassById(id));
    }

    /**
     * 新增应急救援物资种类
     */
    @PreAuthorize("@ss.hasPermi('control:emergencyClass:add')")
    @Log(title = "应急救援物资种类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EmergencyDeviceClass emergencyDeviceClass)
    {
        return toAjax(emergencyDeviceClassService.insertEmergencyDeviceClass(emergencyDeviceClass));
    }

    /**
     * 修改应急救援物资种类
     */
    @PreAuthorize("@ss.hasPermi('control:emergencyClass:edit')")
    @Log(title = "应急救援物资种类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EmergencyDeviceClass emergencyDeviceClass)
    {
        return toAjax(emergencyDeviceClassService.updateEmergencyDeviceClass(emergencyDeviceClass));
    }

    /**
     * 删除应急救援物资种类
     */
    @PreAuthorize("@ss.hasPermi('control:emergencyClass:remove')")
    @Log(title = "应急救援物资种类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(emergencyDeviceClassService.deleteEmergencyDeviceClassByIds(ids));
    }
}
